<template>
  <div>
    <!-- tabs -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>测试</el-breadcrumb-item>
      <el-breadcrumb-item>文件列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- serch -->
    <div class="SHZY-common-search-box">
      <el-row :gutter="20">
        <el-form @submit.native.prevent="">
          <el-col :span="6">
            <el-form-item label="文件类型">
              <el-input
                size="small"
                v-model="formInline.type"
                placeholder="文件类型"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="文件备注">
              <el-input
                size="small"
                v-model="formInline.remark"
                placeholder="文件备注"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="测试下拉框">
              <el-select v-model="formInline.test" placeholder="请选择">
                <el-option v-for="(item,index) in customerOptions" :key="index" :label="item.fullName+'/'+item.enCode" :value="item.enCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button
                size="small"
                type="primary"
                icon="el-icon-search"
                @click="search()"
                >查询</el-button
              >
              <el-button
                size="small"
                icon="el-icon-refresh-right"
                @click="reset()"
                >重置</el-button
              >
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </div>
    <!-- table -->
    <el-card>
      <div class="SHZY-common-head">
        <!-- <el-row :gutter="1">
          <el-col :span="1"
            ><el-button
              size="small"
              type="primary"
              icon="el-icon-plus"
              @click="addOrUpdateHandle()"
              >新增</el-button
            ></el-col
          >
          <el-col :span="1"
            ><el-button size="small" type="text" icon="el-icon-download"
              >导入</el-button
            ></el-col
          >
          <el-col :span="1"
            ><el-button size="small" type="text" icon="el-icon-delete"
              >批量删除</el-button
            ></el-col
          >
        </el-row> -->
        <div>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            @click="addOrUpdateHandle()"
            >新 增</el-button
          >
          <el-button size="small" type="text" icon="el-icon-download"
            >导 入</el-button
          >
          <el-button size="small" type="text" icon="el-icon-delete"
            >批量删除</el-button
          >
        </div>
      </div>
      <div class="table-box" ref="tableBox">
        <el-table
          :data="tableData"
          style="width: 100%"
          :header-cell-style="headercellstyle"
          max-height="tableHeight +'px'"
          v-if="tableHeight"
        >
          <el-table-column prop="type" label="类型" width="180">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.type == 1" type="success">测试</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="备注" width="180">
          </el-table-column>
          <el-table-column prop="fileInfoJosn" label="文件信息">
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="handleEdit(scope.row.id)"
                >编辑</el-button
              >
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="el-pagination">
        <el-pagination
          :page-sizes="[10, 20, 30, 40]"
          :page-size="100"
          :total="total"
        >
        </el-pagination>
      </div>
    </el-card>
    <Form v-if="formVisible" ref="Form" @refresh="refresh"></Form>
  </div>
</template>
<script>
import fileapi from "@/api/file";
import Form from "./Form.vue";
import dictionaryapi from "@/api/dictionary";
export default {
  components: { Form },
  data() {
    return {
      formVisible: false,
      tableHeight: 0,
      formInline: {
        type: "",
        remark: undefined,
        test: undefined,
      },
      tableData: [],
      customerOptions: [],
      total: 0,
      //分页排序参数
      listquery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "",
      },
    };
  },
  created() {
    this.table();
    this.dictionary();
  },
  methods: {
    dictionary() {
      dictionaryapi.getdictionary("customerDataDictionary").then((res) => {
        console.log(res);
        this.customerOptions = res;
      });
    },
    table() {
      fileapi.getFilesInfo().then((res) => {
        console.log(res);
        this.tableData = res;
      });
    },
    headercellstyle({ row, rowIndex }) {
      console.log(rowIndex);
      return "background:#f5f7fa";
    },
    search() {},
    reset() {
      this.formInline.type = undefined;
      this.formInline.remark = undefined;
    },
    refresh(isrRefresh) {
      this.formVisible = false;
      if (isrRefresh) this.reset();
    },
    handleEdit(id) {
      console.log(id);
      this.formVisible = true;
      this.$nextTick(() => {
        this.$refs.Form.init(id);
      });
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
  },
  mounted() {
    this.tableHeight = this.$refs.tableBox.clientHeight - 40;
  },
};
</script>
<style scoped>
.el-pagination {
  background: #fff;
  text-align: right;
}
.table-box {
  height: calc(100vh - 330px); /*示例中顶部区域固定高度190px*/
}
</style>